package com.dwy2002.product;

import com.dwy2002.common.Result;
import com.dwy2002.pojo.dto.users.ProductFavoritesPageDTO;
import com.dwy2002.pojo.po.product.Products;
import com.dwy2002.product.service.IProductFavoritesService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/04/05
 */
@RestController
@RequestMapping("/product/favorites")
@RequiredArgsConstructor
public class ProductFavoritesController {
    private final IProductFavoritesService service;

    /**
     * 返回用户全部商品收藏
     *
     * @param dto 商品收藏DTO
     * @author 杜伟毅
     * @since 2025/3/17 0017 23:58
     */
    @GetMapping("/me")
    public Result<List<Products>> updateNickname(@RequestBody ProductFavoritesPageDTO dto) {
        return service.getProductFavorites(dto);
    }

    /**
     * 收藏商品
     *
     * @param id 商品id
     * @author 杜伟毅
     * @since 2025/3/18 0018 16:01
     */
    @PostMapping("/me/{id}")
    public Result<Void> saveProductFavorites(@PathVariable String id) {
        return service.saveProductFavorites(id);
    }

    /**
     * 取消收藏商品
     *
     * @param id 商品id
     * @author 杜伟毅
     * @since 2025/3/18 0018 16:15
     */
    @DeleteMapping("/me/{id}")
    public Result<Void> cancelFavorites(@PathVariable String id) {
        return service.cancelFavorites(id);
    }
}
